<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改学习资料')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-material-edit" th:object="${material}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">类型：</label>
                <div class="col-sm-8">
                    <select name="type" class="form-control m-b" th:with="type=${@dict.getType('material_res_type')}" style="pointer-events: none;">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{type}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">学习范围：</label>
                <div class="col-sm-8">
                    <select name="range" class="form-control m-b" th:with="type=${@dict.getType('material_range')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{range}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">标题：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">内容介绍：</label>
                <div class="col-sm-8">
                    <textarea name="summary" class="form-control" rows="8" required>[[*{summary}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">标签：</label>
                <div class="col-sm-8">
                    <select id="tags" class="form-control select2-multiple" multiple>
						<option th:each="tag:${tags}" th:value="${tag.name}" th:text="${tag.name}" th:selected="${tag.flag}"></option>
				    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">价格：</label>
                <div class="col-sm-8">
                    <input name="price" th:field="*{price}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否广告：</label>
                <div class="col-sm-8">
                    <select name="ad" class="form-control m-b" th:with="type=${@dict.getType('common_support')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{ad}"></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script type="text/javascript">
        var prefix = ctx + "dict/material";
        $("#form-material-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {

                let data = $('#form-material-edit').serializeArray()
                let tags = $.form.selectSelects("tags")
                data.push({"name": "tags", "value": tags});
                $.operate.save(prefix + "/edit", data);
            }
        }

        $(function() {
            $('#tags').select2({
                placeholder:"请选择标签",
                allowClear: true
            });
        })

    </script>
</body>
</html>